#This script can be directly run from the command line.
#It counts posts by status and prints the results.
#This is used for analysis of a specific dataset.

import sys
import io
import re
import shlex
import Parser
import Post
import FileIO

def main():
	fileStream = FileIO.openDataSetFile(FileIO.READ_MODE)
	
	#Comment the following line if the dataset being counted does not have a header
	Parser.readHeader(fileStream)
	
	postCount = 0
	openCount = 0
	offTopicCount = 0
	notConstructiveCount = 0
	notARealQuestionCount = 0
	tooLocalizedCount = 0
	
	#For each post
	while (not Parser.isEndOfFile(fileStream)):
		newPost = Parser.readPost(fileStream)
		postType =  newPost.openStatus
		#Increment the count variable corresponding to the post status
		if(postType == Post.PostStatusEnum.OPEN):
			openCount = openCount + 1
		elif(postType == Post.PostStatusEnum.OFF_TOPIC):
			offTopicCount = offTopicCount + 1
		elif(postType == Post.PostStatusEnum.NOT_CONSTRUCTIVE):
			notConstructiveCount = notConstructiveCount + 1
		elif(postType == Post.PostStatusEnum.NOT_A_REAL_QUESTION):
			notARealQuestionCount = notARealQuestionCount + 1
		elif(postType == Post.PostStatusEnum.TOO_LOCALIZED):
			tooLocalizedCount = tooLocalizedCount + 1
		postCount = postCount + 1
		#Used to measure progress
		print str(postCount) + "   " + newPost.postID
		
	#Calculate percentages
	openPercent = float(openCount) / float(postCount)
	offTopicPercent = float(offTopicCount) / float(postCount)
	notConstructivePercent = float(notConstructiveCount) / float(postCount)
	notARealQuestionPercent = float(notARealQuestionCount) / float(postCount)
	tooLocalizedPercent = float(tooLocalizedCount) / float(postCount)
	
	#Print the results
	print ""
	print "Posts                       : " + str(postCount)
	print "Open Posts                  : " + str(openCount)
	print "Off Topic Posts             : " + str(offTopicCount)
	print "Not Constructive Posts      : " + str(notConstructiveCount)
	print "Not a Real Question Posts   : " + str(notARealQuestionCount)
	print "Too Localized Posts         : " + str(tooLocalizedCount)
	print ""
	print "Open Percent                : " + str(openPercent)
	print "Off Topic Percent           : " + str(offTopicPercent)
	print "Not Constructive Percent    : " + str(notConstructivePercent)
	print "Not a Real Question Percent : " + str(notARealQuestionPercent)
	print "Too Localized Percent       : " + str(tooLocalizedPercent)
	print ""
	
main()